package com.trs.publish.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.trs.publish.domain.EsSearch;
import com.trs.publish.domain.SearchParam;
import com.trs.publish.domain.User;

@Controller
public class SearchController {
	@RequestMapping(value = "/toSearch")
	public ModelAndView toSearch(ModelAndView mav) {
		mav.setViewName("search/search");
		return mav;
	}  
	
	@PatchMapping(value = "/search")
	@ResponseBody
    public PageInfo<EsSearch> search(@RequestBody SearchParam searchParam) {
		String keyword = searchParam.getKeyword();
		//获取资源分类的Map
		List<EsSearch> list = new ArrayList<>();
		for(int i=0;i<10;i++){
			EsSearch es = new EsSearch();
			es.setId(String.valueOf(i));
			es.setTitle("我爱北京天安门,天安门上太阳升");
			es.setContent("天安门，坐落在中华人民共和国首都北京市的中心、\r\n" + 
					"故宫的南端，与天安门广场以及人民英雄纪念碑、毛主席纪念堂、人民大会堂、中国国家博物\r\n" + 
					"馆隔长安街相望，占地面积4800平方米，以杰出的建筑艺术和特殊的政治地位为世人所瞩目\r\n" + 
					"。天安门是明清...");
			es.setContent(es.getContent().replaceAll(keyword, "<font color=\"red\">"+keyword+"</font>"));
			es.setTitle(es.getTitle().replaceAll(keyword, "<font color=\"red\">"+keyword+"</font>"));
			list.add(es);
		}
		PageInfo<EsSearch> pageInfo = new PageInfo<>(list);
		pageInfo.setLastPage(10);
        return pageInfo;
    }  
	
}
